<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>

    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane label="账号登录" name="account">
          <template #label>
            <div class="label">
              <el-icon :size='15'>
                <User />
              </el-icon>
              <span>账号登录</span>
            </div>
          </template>
          <pannelAccount ref="accountRef" />
        </el-tab-pane>

        <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <div class="label">
              <el-icon :size='15'>
                <Iphone />
              </el-icon>
              <span>手机登录</span>
            </div>
          </template>
          <pannelPhone />
        </el-tab-pane>
      </el-tabs>
    </div>

    <div class="control-account">
      <el-checkbox v-model="isRememberPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button class="login-btn" type="primary" @click="handleLoginClick">登录</el-button>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import PannelPhone from './pannel-phone.vue'
import PannelAccount from './pannel-account.vue'
import { localCache } from '@/utils/cache'




const isRememberPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
const activeName = ref('account')

watch(isRememberPwd, (nweValue) => {
  localCache.setCache('isRemPwd', nweValue)
})

const accountRef = ref<InstanceType<typeof PannelAccount>>()
function handleLoginClick() {
  if (activeName.value === 'account') {
    if (!isRememberPwd.value) {
      localCache.removeCache('name')
      localCache.removeCache('password')
    }

    accountRef.value?.loginAction(isRememberPwd.value)

  } else {
    console.log("手机登录")
  }

}



</script>

<style lang="less" scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
  }

  .control-account {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;
  }
}
</style>